package com.tang.h2_demo.global.response;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.SmartLifecycle;
import org.springframework.stereotype.Component;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;

import java.util.ArrayList;
import java.util.List;

@Component
public class GlobleResponseHandlerInit implements SmartLifecycle {

    @Autowired
    private RequestMappingHandlerAdapter adapter;

    @Override
    public void start() {
        List<HandlerMethodReturnValueHandler> wrapper = new ArrayList<>();
        List<HandlerMethodReturnValueHandler> handlers = adapter.getReturnValueHandlers();
        for (HandlerMethodReturnValueHandler handler : handlers) {
            wrapper.add(new GlobalReturnValueHandlerWrapper(handler));

        }
        adapter.setReturnValueHandlers(wrapper);
    }

    @Override
    public void stop() {

    }

    @Override
    public boolean isRunning() {
        return false;
    }
}
